import { IsEmail, IsIn, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID, MaxLength } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { DEPT_STATUS_VALUES, type ICreateDept } from '@nbase/shared';
import { Type } from 'class-transformer';

/**
 * 创建部门 DTO
 */
export class CreateDeptDto implements ICreateDept {
  @ApiProperty({ description: '部门编码', example: 'DEPT_TECH' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  code!: string;

  @ApiProperty({ description: '部门名称', example: '技术部' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  name!: string;

  @ApiPropertyOptional({ description: '父部门ID', example: '550e8400-e29b-41d4-a716-446655440000' })
  @IsOptional()
  @IsUUID()
  parentId?: string;

  @ApiPropertyOptional({ description: '排序', example: 1 })
  @IsOptional()
  @IsInt()
  sort?: number;

  @ApiPropertyOptional({ description: '负责人', example: '张三' })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  leader?: string;

  @ApiPropertyOptional({ description: '联系电话', example: '13800138000' })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  phone?: string;

  @ApiPropertyOptional({ description: '邮箱', example: 'tech@example.com' })
  @IsOptional()
  @IsEmail()
  @MaxLength(50)
  email?: string;

  @ApiPropertyOptional({
    description: '状态（1.启用 2.禁用）',
    example: 1,
    enum: DEPT_STATUS_VALUES,
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @IsIn(DEPT_STATUS_VALUES)
  status?: number;

  @ApiPropertyOptional({ description: '描述', example: '技术研发部门' })
  @IsOptional()
  @IsString()
  @MaxLength(256)
  description?: string;
}

